const express = require("express");
const cors = require("cors");
const bodyParser = require("body-parser");
const { generateToken04 } = require("./zegoServerAssistant");
//创建一个express应用
const app = express();
//使用 CORS 中间件
app.use(cors());
app.use(bodyParser.json({ limit: "20mb" })); // for parsing application/json

//即构获取token
app.post("/api/zgVideo/getToken", function (request, response) {
  getZgVideoToken(request, response);
});
function getZgVideoToken(request, response) {
  let postData = "";
  request.on("data", function (chuck) {
    postData += chuck;
  });
  request.on("end", function () {
    console.log("------------", postData);
    let data = JSON.parse(postData);
    const token = generateToken04(
      data.appId,
      data.userId,
      data.secret,
      86400,
      ""
    );
    console.log("token:", token);
    response.send(token);
  });
}
//http
const port = "5003";
app.listen(port, () => {
  console.log("listening on 5003");
});